<template>
  <div class="page-search">
    <search-form v-bind="searchFormConfig" v-model="formDate">
      <template #header v-if="searchFormConfig.showHeader"> </template>
      <template #footer v-if="searchFormConfig.showFooter">
        <div class="btn">
          <el-button @click="handlerSearch" size="mini">查询</el-button>
          <el-button @click="resetSearchForm" size="mini" type="primary">重置</el-button>
        </div>
      </template>
    </search-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue"
import SearchForm from "@/base_ui/form/index"
export default defineComponent({
  components: {
    SearchForm,
  },
  props: {
    searchFormConfig: {
      type: Object,
      required: true,
    },
  },

  emits: ["newSearchEvent"],
  setup(props, { emit }) {
    const originDate: any = ref({})
    // 获取配置文件传递过里啊的表单属性
    props.searchFormConfig.searchFormItems.forEach((formItem: any) => {
      originDate[formItem.field] = ""
    })
    // 动态更改表单属性
    const formDate = originDate

    // 重置按钮
    const resetSearchForm = () => {
      Object.keys(formDate.value).forEach((key) => {
        formDate.value[key] = ""
      })
      emit("newSearchEvent", formDate.value)
    }

    // 搜索按钮
    const handlerSearch = () => {
      console.log("发出搜索事件")
      emit("newSearchEvent", formDate.value)
    }

    return {
      formDate,
      resetSearchForm,
      handlerSearch,
    }
  },
})
</script>
<style lang="less" scoped>
.btn {
  padding: 0 0 20px 50px;
}
.page-search {
  background-color: #fff;
}
</style>
